using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using ChessGameV2.Scenes;

namespace ChessGameV2
{
    public enum GameScene { Start, LoadGame, Setting, Playing, Quit };
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        GameControl game;
        public static GameScene gameScene;
        public static MouseState lastMouseState;    // Trang thai chuot cuoi
        public static MouseState currentMouseState; // Trang thai chuot dau
        StartScene startScene;
        //PlayScene playscrene;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            this.Window.Title = "[Game] Chess AI";
            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferHeight = 530;
            graphics.PreferredBackBufferWidth = 500;
            this.IsMouseVisible = true;
            this.Window.AllowUserResizing = false;
            gameScene = GameScene.Start;
            
        }
        protected override void Initialize()
        {
            base.Initialize();
        }
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            startScene = new StartScene(spriteBatch);
            //playscrene = new PlayScene(spriteBatch);
            startScene.LoadContent(Content);
            //playscrene.LoadContent(Content);
            game = new GameControl(spriteBatch);
            game.LoadContent(Content);
            Sounds.LoadContent(Content);
        }
        protected override void UnloadContent()
        {
        }
        protected override void Update(GameTime gameTime)
        {
            currentMouseState = Mouse.GetState();
            if(gameScene == GameScene.Start)
            {
                game.gameState = GameState.Start;
                startScene.Update();
                
                //playscrene.update();
            }
            else if (gameScene == GameScene.LoadGame)
            {

            }
            else if (gameScene == GameScene.Setting)
            {
                
            }
            else if (gameScene == GameScene.Quit)
            {
                this.Exit();
            }
            else // Playing
            {
                game.Update(gameTime);
                
            }
            lastMouseState = currentMouseState;
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            base.Draw(gameTime);
            spriteBatch.Begin();
            if (gameScene == GameScene.Start)
            {
                startScene.Draw();
            }
            else if (gameScene == GameScene.LoadGame)
            {

            }
            else if (gameScene == GameScene.Setting)
            {
                //playscrene.DrawSetting();
            }
            else if (gameScene == GameScene.Playing)
            {
                game.Draw();
                //playscrene.DrawSetting();
            }
            spriteBatch.End();
            
        }
    }
}
